package com.hdax.dm.common.utils;

import com.hdax.dm.constants.ResultEnumCode;
import com.hdax.dm.exceptions.DmException;

public class ResponseUtil<T> {

    //成功响应
    public static<T> CommonResponse returnSuccess(T data){
        return new CommonResponse(data);
    }

    public static<T> CommonResponse returnSuccess(String msg){
        return new CommonResponse("0000",msg);
    }

    //失败响应
    public static CommonResponse returnFail(String errorCode, String msg){
        return new CommonResponse(errorCode, msg);
    }

    public static CommonResponse returnFail(ResultEnumCode code){
        return new CommonResponse(code.getErrorCode(), code.getMessage());
    }

    public static CommonResponse returnFail(DmException exception){
        return returnFail(exception.getErrorCode(),exception.getMessage());
    }


}
